
/**
\file
Definition of the sun::lua::function_proxy helper struct.
\author Sean Tromans
*/

#ifndef	SUN_LUA_FUNCTION_PROXY_HPP
#define	SUN_LUA_FUNCTION_PROXY_HPP

#include <sun/lua/lua_fwd.hpp>

#define	NMN_DEFINE_FUNCTION_PROXY(z, n, _)	\
	template < BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_INC(n), class T) >	\
	inline R operator()( BOOST_PP_ENUM_BINARY_PARAMS_Z(z, BOOST_PP_INC(n), T, const & p) )	\
	{	\
		return luabind::call_function<R>( functor, BOOST_PP_ENUM_PARAMS_Z(z, BOOST_PP_INC(n), p) ); \
	}

namespace sun
{

	namespace lua
	{

		/**
		Helper functor to allow luabind::objects to be used as functor objects.
		\author Sean Tromans
		*/
		template< typename R >
		struct function_proxy
		{
			/**
			Constructor
			@param o The object to use as a functor.
			\author Sean Tromans
			*/
			function_proxy( luabind::object const & o )
				:		functor( o )
			{}

			inline R operator()( )
			{
				return luabind::call_function<R>( functor );
			}

			BOOST_PP_REPEAT( BOOST_PP_INC(10), NMN_DEFINE_FUNCTION_PROXY, 0 );

			luabind::object functor;
		};

	};

};

#undef	NMN_DEFINE_FUNCTION_PROXY

#endif	//SUN_LUA_FUNCTION_PROXY_HPP
